<template>
    <div class="head">
        <div class="head-cont">
            <div class="head-cont-c">
                <img class="logo" src="../../static/images/logo.png" width="280px">
                <div class="nav">
                    <!--activeClass 设置 链接激活时使用的 CSS 类名。默认值可以通过路由的构造选项 linkActiveClass 来全局配置。默认值: "router-link-active" -->
                    <router-link class="nav-item shouye" :to="{path:'/index', activeClass: 'on'}">首页</router-link>
                    <router-link class="nav-item yonghu" v-if="menuUsers" :to="{path:'/user', activeClass: 'on'}">用户</router-link>
                    <router-link class="nav-item juese" v-if="menuRoles" :to="{path:'/role', activeClass: 'on'}">角色</router-link>
                    <router-link class="nav-item quanxian" v-if="menuPermissions" :to="{path:'/grant', activeClass: 'on'}">权限</router-link>
                    <router-link class="nav-item xitong" v-if="menuSystems" :to="{path:'/system', activeClass: 'on'}">系统</router-link>
                    <router-link class="nav-item zidian" v-if="menuDictionaries" :to="{path:'/dictionary', activeClass: 'on'}">字典</router-link>
                    <router-link class="nav-item rizhi" v-if="menuLogs" :to="{path:'/log', activeClass: 'on'}">日志</router-link>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import "../../static/css/main.css";
export default {
  name: "heads",
  data() {
    return {
      menuUsers: "",
      menuRoles: "",
      menuPermissions: "",
      menuSystems: "",
      menuDictionaries: "",
      menuLogs: ""
    };
  },
  mounted: function() {
    this.$nextTick(() => {
      //导航切换样式
      $(".nav-item").click(function() {
        $(this)
          .addClass("on")
          .siblings()
          .removeClass("on");
      });
      //调用全局方法根据权限值显示对应信息
      this.grantType();
    });
  },
  methods: {
    goIndex() {
      this.$router.push("/index");
      $(this.$el)
        .find(".shouye")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    goUser() {
      this.$router.push("/user");
      $(this.$el)
        .find(".yonghu")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    goRole() {
      this.$router.push("/role");
      $(this.$el)
        .find(".juese")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    goGrant() {
      this.$router.push("/grant");
      $(this.$el)
        .find(".quanxian")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    goSystem() {
      this.$router.push("/system");
      $(this.$el)
        .find(".xitong")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    goDictionary() {
      this.$router.push("/dictionary");
      $(this.$el)
        .find(".zidian")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    goLog() {
      this.$router.push("/log");
      $(this.$el)
        .find(".rizhi")
        .addClass("on")
        .siblings()
        .removeClass("on");
    },
    grantType() {
      let grantLength = 0;
      let permissions = appDB.get("userInfo").permissions; 
      for (grantLength = 0; grantLength < permissions.length; grantLength++) {
        //遍历权限列表
        // console.info(permissions[grantLength]);
        if (permissions[grantLength].permission == "menu:users") {
          //菜单权限
          this.menuUsers = true;
        } else if (permissions[grantLength].permission == "menu:roles") {
          this.menuRoles = true;
        } else if (permissions[grantLength].permission == "menu:permissions") {
          this.menuPermissions = true;
        } else if (permissions[grantLength].permission == "menu:systems") {
          this.menuSystems = true;
        } else if (permissions[grantLength].permission == "menu:dictionaries") {
          this.menuDictionaries = true;
        } else if (permissions[grantLength].permission == "menu:logs") {
          this.menuLogs = true;
        } else if (permissions[grantLength].permission == "users:read") {
          //功能权限
          this.usersRead = true;
        } else if (permissions[grantLength].permission == "users:add") {
          this.usersAdd = true;
        } else if (permissions[grantLength].permission == "users:edit") {
          this.usersEdit = true;
        } else if (permissions[grantLength].permission == "users:delete") {
          this.usersDelete = true;
        } else if (
          permissions[grantLength].permission == "users:update_password"
        ) {
          this.usersUpdate_password = true;
        } else if (permissions[grantLength].permission == "roles:read") {
          this.rolesRead = true;
        } else if (permissions[grantLength].permission == "roles:add") {
          this.rolesAdd = true;
        } else if (permissions[grantLength].permission == "roles:edit") {
          this.rolesEdit = true;
        } else if (permissions[grantLength].permission == "roles:delete") {
          this.rolesDelete = true;
        } else if (permissions[grantLength].permission == "roles:author") {
          this.rolesAuthor = true;
        } else if (permissions[grantLength].permission == "permissions:read") {
          this.permissionsRead = true;
        } else if (permissions[grantLength].permission == "permissions:add") {
          this.permissionsAdd = true;
        } else if (permissions[grantLength].permission == "permissions:edit") {
          this.permissionsEdit = true;
        } else if (
          permissions[grantLength].permission == "permissions:delete"
        ) {
          this.permissionsDelete = true;
        } else if (permissions[grantLength].permission == "dictionaries:read") {
          this.dictionariesRead = true;
        } else if (permissions[grantLength].permission == "dictionaries:add") {
          this.dictionariesAdd = true;
        } else if (permissions[grantLength].permission == "dictionaries:edit") {
          this.dictionariesEdit = true;
        } else if (
          permissions[grantLength].permission == "dictionaries:delete"
        ) {
          this.dictionariesDelete = true;
        } else if (permissions[grantLength].permission == "logs:read") {
          this.logsRead = true;
        } else if (permissions[grantLength].permission == "sysparams:read") {
          this.sysparamsRead = true;
        } else if (permissions[grantLength].permission == "sysparams:add") {
          this.sysparamsAdd = true;
        } else if (permissions[grantLength].permission == "sysparams:edit") {
          this.sysparamsEdit = true;
        } else if (permissions[grantLength].permission == "sysparams:delete") {
          this.sysparamsDelete = true;
        } else {
        }
      }
    }
  }
};
</script>

<style scoped>

</style>
